<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
   pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@page import="support.*,java.util.*"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<link rel="stylesheet" type="text/css" href="layout.css" />
<title>Country of Citizenship</title>
</head>
<body>

   <%
      String path1 = config.getServletContext().getRealPath("countries.txt");
      String path2 = config.getServletContext().getRealPath(
            "universities.txt");
      String path3 = config.getServletContext().getRealPath(
            "specializations.txt");
      String path4 = config.getServletContext().getRealPath("months.txt");
      //getCountries returns a vector of the universities to be used for choosing citizenship

      support s = new support();
      student applicant = new student();
      applicant.setCountryVector(s.getCountries(path1));
      applicant.setUniversityVector(s.getUniversities(path2));
      applicant.setSpecializationVector(s.getSpecializations(path3));
      applicant.setMonthVector(s.getCountries(path4));
      applicant.name = applicant.new Name(request.getParameter("fName"),
            request.getParameter("mName"), request.getParameter("lName"));

      session.setAttribute("applicant", applicant);
   %>

   <p>
      Name:
      <%=applicant.name.toString()%><br />
   </p>
   <hr>

   <p><b>Please Select your country of citizenship:</b></p>
   <table border="1">
      <%
         int size = applicant.getCountryVector().size(), rows, cell1, cell2, cell3;

         if (applicant.getCountryVector().size() % 3 == 0)
            rows = (int) (size / 3);
         else
            rows = (int) (size / 3) + 1;

         for (int i = 0; i < rows; i++) {
            cell1 = i;
            cell2 = i + rows;
            cell3 = i + 2 * rows;
      %>
      <tr>
         <td><a href="countryResidence.jsp?citizenship=<%=cell1%>"><%=applicant.getCountryVector().get(cell1)%></a></td>
         <%
            if (cell2 < size) {
         %>
         <td><a href="countryResidence.jsp?citizenship=<%=cell2%>"><%=applicant.getCountryVector().get(cell2)%></a></td>
         <%
            }
               if (cell3 < size) {
         %>
         <td><a href="countryResidence.jsp?citizenship=<%=cell3%>"><%=applicant.getCountryVector().get(cell3)%></a></td>
         <%
            }
         %>
      </tr>
      <%
         }
      %>
   </table>